#ifndef COMMON_REDIS_REDIS_H_
#define COMMON_REDIS_REDIS_H_
#include <string>
#include <map>
#include "SyncRedisClient.h"


using std::string;
using std::map;

class Redis
{
public:
	Redis()
	{
		redis_client_ = new RedisClient( "127.0.0.1", 6379 );
	}
	virtual ~Redis()
	{
		delete redis_client_;
		redis_client_ = NULL;
	};


public:
	int Get(const string& key, string& out);
	int Smembers( const string& key, vector<string>& out );
	int Scard( const string& key );
	int Scard( const string& key, uint32_t& count);
	int Sismember( const string& key, const string& value, bool& is_member);
	int Hgetall( const string& key, vector< pair<string,string> >& values );
	int Hgetall( const string& key, map<string,string>& values );
	int Hget( const string& key, const string& field, string& value );
	int Hexists( const string& key, const string & field );
	int Hexists( const string& key, const string& field, bool& exist);

	int Set(const string& key, const string& value);
	int Sadd( const string& key, const string& value );
	int Srem( const string& key, const string& value );
	int Hmset( const string& key, const vector< pair<string,string> >& values );
	int Hset( const string& key, const string& field, const string& value );
	int Hdel( const string& key, const string& field );

	int DelKey( const string& key );

	int Publish( const string& channel, const string& value );

	int Incr( const string& key, int n );
	int Incr( const string& key, int n, int64_t& ret_val);

	int HIncrBy( const string& key, const string& field, int n );
	int HIncrBy( const string& key, const string& field, int n, int64_t& ret_val);

	int Keys(const string& key, vector<string>& out);

protected:
	string TransferredStringMeaning(const string& src);
	redisReply* HmSetSelectWithParaCount( const string& key, const vector< pair<string,string> >& values );


	RedisClient* redis_client_;
};



#endif

